D:\a\csshw\csshw\src\utils\debug.rs
Line | Count | Source |
1 | | //! Implements string representations for INPUT_RECORD related structs. |
2 | | //! For debugging only. |
3 | | |
4 | | use windows::Win32::System::Console::{INPUT_RECORD_0, KEY_EVENT_RECORD, KEY_EVENT_RECORD_0}; |
5 | | |
6 | | /// String represation trait. |
7 | | /// |
8 | | /// As we cannot implement foreign traits for foreign structs |
9 | | /// we can't implement the `Display` or `Debug`` traits for the windows |
10 | | /// structs. |
11 | | pub trait StringRepr { |
12 | | /// Returns a string representation of the struct. |
13 | | fn string_repr(&self) -> String; |
14 | | } |
15 | | |
16 | | impl StringRepr for KEY_EVENT_RECORD_0 { |
17 | | /// Returns a string representation of a [KEY_EVENT_RECORD_0][1] showing |
18 | | /// which unicode character it represents. |
19 | | /// |
20 | | /// [1]: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/Console/union.KEY_EVENT_RECORD_0.html |
21 | 0 | fn string_repr(&self) -> String { |
22 | 0 | return format!("unicode_char: {}", unsafe { self.UnicodeChar }); |
23 | 0 | } |
24 | | } |
25 | | |
26 | | impl StringRepr for KEY_EVENT_RECORD { |
27 | | /// Returns a string representation of a [KEY_EVENT_RECORD][1] showing |
28 | | /// all relevant attributes. |
29 | | /// |
30 | | /// [1]: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/Console/struct.KEY_EVENT_RECORD.html |
31 | 0 | fn string_repr(&self) -> String { |
32 | 0 | return [ |
33 | 0 | format!("key_down: {}", self.bKeyDown.as_bool()), |
34 | 0 | format!("repeat_count: {}", self.wRepeatCount), |
35 | 0 | format!("virtual_key_code: 0x{:x}", self.wVirtualKeyCode), |
36 | 0 | format!("virtual_scan_code: 0x{:x}", self.wVirtualScanCode), |
37 | 0 | format!("char: 0x{:x}", unsafe { self.uChar.UnicodeChar }), |
38 | 0 | format!("control_key_state: {}", self.dwControlKeyState), |
39 | 0 | ] |
40 | 0 | .join(",\n"); |
41 | 0 | } |
42 | | } |
43 | | |
44 | | impl StringRepr for INPUT_RECORD_0 { |
45 | | /// Returns a string representation of a [INPUT_RECORD_0][1]. |
46 | | /// |
47 | | /// Note: we expect a [KeyEvent][2]. |
48 | | /// |
49 | | /// [1]: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/Console/union.INPUT_RECORD_0.html |
50 | | /// [2]: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/Console/struct.KEY_EVENT_RECORD.html |
51 | 0 | fn string_repr(&self) -> String { |
52 | 0 | return unsafe { self.KeyEvent }.string_repr(); |
53 | 0 | } |
54 | | } |